package com.zhou;

import java.util.Scanner;

/**
 * T19
 *
 * @author zhouxianfeng
 * @date 2021-9-6
 */
public class T19 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        Integer[] nums = new Integer[num];
        for (int i = 0; i < num; i++) {
            nums[i] = scanner.nextInt();
        }
        resolve1(nums);
    }

    /**
     * 暴力破解
     *
     * @param m
     */
    public static void resolve(Integer[] m) {
        int length = m.length;
        int max = 0;
        for (int i = 1; i <= length; i++) {
            for (int j = 0; j < length; j++) {
                int min = m[j];
                int sum = 0;
                for (int k = j; k < i; k++) {
                    sum += m[k];
                    if (min > m[k]) {
                        min = m[k];
                    }
                }
                if (max < min * sum) {
                    max = min * sum;
                }
            }

        }
        System.out.println(max);
    }

    /**
     * 找最小值解法
     *
     * @param m
     */
    public static void resolve1(Integer[] m) {

        int length = m.length;
        int max = 0;

        for (int i = 0; i < length; i++) {
            int res = res(m, i);
            if (max < res) {
                max = res;
            }
        }
        System.out.println(max);
    }

    public static int res(Integer[] m, int j) {
        int index = j;
        int sum = m[j];
        int target = m[j];
        boolean left = true;
        boolean right = true;
        int i = 0;
        while (left || right) {
            i++;
            if (left) {
                if (index - i >= 0 && target <= m[index - i]) {
                    sum += m[index - i];
                } else {
                    left = false;
                }
            }
            if (right) {
                if (index + i < m.length && target <= m[index + i]) {
                    sum += m[index + i];
                } else {
                    right = false;
                }
            }
        }
        return target * sum;

    }

}
